/*
 * 
 */
package com.oniontech.stamptour.common.ui;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.oniontech.stamptour.R;

// TODO: Auto-generated Javadoc
/**
 * The Class CustomDialog.
 * 
 * @author limsy
	 * @since 2013/02/04
 */
public class CustomDialog
{

	/** The Constant BTN_CANCEL. */
	public final static int BTN_CANCEL = R.id.btn_dial_cancel;
	
	/** The Constant BTN_CONFIRM. */
	public final static int BTN_CONFIRM = R.id.btn_dial_confirm;
	
	/** The dialog. */
	Dialog dialog;

	/** The btn_cancel. */
	Button btn_confirm, btn_cancel;

	/** The text_msg. */
	TextView text_title, text_msg, text_msg_top;
	
	/** The editText. */
	EditText edit_text;
	
	/** The edit_text_2. */
	EditText edit_text_2;

	/** The context. */
	Context context;
	
	/**
	 * Instantiates a new custom dialog.
	 * 
	 * @param context
	 *            the context
	 */
	public CustomDialog(Context context)
	{
		// TODO Auto-generated constructor stub
		this.context = context;

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.custom_dialog, null);

		dialog = new Dialog(context);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.getWindow().setBackgroundDrawable(
				new ColorDrawable(Color.TRANSPARENT));
		dialog.setContentView(layout);
		dialog.setCancelable(true);

		btn_confirm = (Button) layout.findViewById(R.id.btn_dial_confirm);
		btn_cancel = (Button) layout.findViewById(R.id.btn_dial_cancel);

		text_title = (TextView) layout.findViewById(R.id.dialogTitle);
		text_msg = (TextView) layout.findViewById(R.id.dialogMsg);
		text_msg_top = (TextView) layout.findViewById(R.id.dialogMsgTop);
		
		edit_text = (EditText) layout.findViewById(R.id.dialogEdit);
		edit_text_2 = (EditText) layout.findViewById(R.id.dialogEdit_2);
	}

	/**
	 * Sets the cancelable.
	 * 
	 * @param mode
	 *            the new cancelable
	 */
	public void setCancelable(Boolean mode)
	{
		dialog.setCancelable(mode);
	}

	/**
	 * Sets the custom dialog.
	 * 
	 * @param click
	 *            the click
	 * @param mode
	 *            the mode
	 */
	public void setCustomDialog(OnClickListener click, Boolean mode)
	{

		btn_confirm.setOnClickListener(click);
		btn_cancel.setOnClickListener(click);

		if (!mode)
		{
			btn_cancel.setVisibility(View.GONE);
		}
	}

	/**
	 * Sets the dialog title.
	 * 
	 * @param msg
	 *            the new dialog title
	 */
	public void setDialogTitle(String msg)
	{
		text_title.setVisibility(View.VISIBLE);
		text_title.setText(msg);
	}

	/**
	 * Sets the dialog msg.
	 * 
	 * @param msg
	 *            the new dialog msg
	 */
	public void setDialogMsg(String msg)
	{
		text_msg.setText(msg);
	}
	
	/**
	 * Sets the dialog msg top.
	 *
	 * @param msg the new dialog msg top
	 */
	public void setDialogMsgTop(String msg) {
		text_msg_top.setVisibility(View.VISIBLE);
		text_msg_top.setText(msg);
	}

	/**
	 * Sets the btn text.
	 * 
	 * @param confirm
	 *            the confirm
	 * @param cancel
	 *            the cancel
	 */
	public void setBtnText(String confirm, String cancel)
	{
		btn_confirm.setText(confirm);
		btn_cancel.setText(cancel);
	}
	
	/**
	 * Sets the edits the visiable.
	 *
	 * @param mode the new edits the visiable
	 */
	public void setEditVisiable(int mode) {
		edit_text.setVisibility(mode);
	}
	
	/**
	 * Sets the edits the text.
	 *
	 * @param msg the new edits the text
	 */
	public void setEditText(String msg) {
		edit_text.setText(msg);
	}
	
	/**
	 * Gets the edits the view.
	 *
	 * @return the edits the view
	 */
	public EditText getEditView(){
		return edit_text;
	}
	
	/**
	 * Sets the edit2 visible.
	 *
	 * @param mode the new edit2 visible
	 */
	public void setEdit2Visible(int mode) {
		edit_text_2.setVisibility(mode);
	}
	
	/**
	 * Sets the edit2 text.
	 *
	 * @param msg the new edit2 text
	 */
	public void setEdit2Text(String msg) {
		edit_text_2.setText(msg);
	}
	
	/**
	 * Gets the edits the view2.
	 *
	 * @return the edits the view2
	 */
	public EditText getEditView2(){
		return edit_text_2;
	}
	
	/**
	 * Gets the edits the text.
	 *
	 * @return the edits the text
	 */
	public String getEditText() {
		return edit_text.getText().toString();
	}

	/**
	 * Show.
	 */
	public void Show()
	{
		dialog.show();
	}

	/**
	 * Dismiss.
	 */
	public void Dismiss()
	{
		dialog.dismiss();
	}

	/**
	 * Gets the dialog.
	 * 
	 * @return the dialog
	 */
	public Dialog getDialog()
	{
		return dialog;
	}

	/**
	 * Checks if is show.
	 * 
	 * @return the boolean
	 */
	public Boolean isShow()
	{
		return dialog.isShowing();
	}
}
